﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using Weixin.MP.UI;

namespace Weixin.MP.Web.Filters
{
    public class DwzJsonExceptionAttribute : HandleErrorAttribute
    {

        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
            filterContext.HttpContext.Response.Write(JsonConvert.SerializeObject(new DwzJsonResult
            {
                StatusCode = DwzStatusCode.Error,
                Message = string.Format("操作失败：{0}", filterContext.Exception.Message)
            }));
            filterContext.HttpContext.Response.End();

        }
        ////当方法执行时
        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    //base.OnActionExecuting(filterContext);
        //    try
        //    {
        //        var sess = filterContext.RequestContext.HttpContext.Session["login"];
        //        if (sess == null || sess.ToString() != "True") filterContext.Result = new RedirectResult("/Home/login");
        //    }
        //    catch
        //    {
        //        filterContext.Result = new RedirectResult("/Shared/Error");
        //    }
        //}

        ////当方法执行完毕
        //public override void OnActionExecuted(ActionExecutedContext filterContext)
        //{
        //    base.OnActionExecuted(filterContext);
        //}

    }

}